package com.yunsom.testdemo.design.singleton;

/**
 * @author Xbao
 * @version 1.0
 * @description
 * 采用双锁机制，安全且在多线程情况下能保持高性能。
 * getInstance() 的性能对应用程序很关键。
 * @date 2021/3/9 19:21
 */
public class DoubleLockSingleton {

  private volatile static DoubleLockSingleton instance;

  private DoubleLockSingleton(){}

  public static DoubleLockSingleton getInstance(){
    if(instance == null){
      synchronized (DoubleLockSingleton.class){
        if(instance == null){
          instance = new DoubleLockSingleton();
        }
      }
    }
    return instance;
  }

}
